package xkp.lesson2;

public class TestSynMethod {
    public static void main(String[] args) throws InterruptedException {
        MyClass myClass = new MyClass();
        //内名内部类可以访问外部类的一切资源
        new Thread(){
            @Override
            public void run() {
                for(int i = 1; i <= 100; i++){
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    myClass.addCount();
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for(int i = 1; i <= 100; i++){
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    myClass.addCount();
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for(int i = 1; i <= 100; i++){
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    myClass.addCount();
                }
            }
        }.start();

        Thread.sleep(5000);
        System.out.println(myClass.getCount());
    }
}
